
package com.zhu.storesmanager;


import com.zhu.storesmanager.models.VisitTaskInfo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

/**
 * 督导门店拜访内容选择界面
 */
public class SvSelectVisitContentActivity extends Activity {

    private String[] mMenuStr = null; // 菜单文本
    private int[] mImageId = {
            R.drawable.incon_index_remind_foucus, R.drawable.incon_index_remind_foucus,
            R.drawable.incon_index_remind_foucus, R.drawable.incon_index_remind_foucus,
            R.drawable.incon_index_remind_foucus, R.drawable.incon_index_remind_foucus,
            R.drawable.incon_index_remind_foucus
    }; // 图片资源ID
    private VisitTaskInfo mVisitTaskInfo = null; //拜访门店数据

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Parcelable parcelable = getIntent().getParcelableExtra("info");
        mVisitTaskInfo = (VisitTaskInfo) parcelable;
        setContentView(R.layout.activity_sv_selectvisitcontent);
        setupViews();
    }

    /**
     * 设置界面
     */
    private void setupViews() {
        ((TextView) findViewById(R.id.title_text)).setText(R.string.select_visit_content);
        mMenuStr = this.getResources().getStringArray(R.array.visit_content_menu);
        GridView gridview = (GridView) findViewById(R.id.girdview);   
        gridview.setAdapter(new GridAdapter());
        findViewById(R.id.svcontent_bottom_back).setOnClickListener(new OnClickListener(){ //返回处理
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        gridview.setOnItemClickListener(new OnItemClickListener(){ //菜单点击监听
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putParcelable("info", mVisitTaskInfo);
                intent.putExtras(bundle);
                switch(arg2){
                    case 0: //门店出样
                        intent.setClass(SvSelectVisitContentActivity.this, SvStoreSampleActivity.class);
                        SvSelectVisitContentActivity.this.startActivity(intent);
                        break;
                    case 1: //门店展台
                    	intent.setClass(SvSelectVisitContentActivity.this, SvStoreBoothActivity.class);
                        SvSelectVisitContentActivity.this.startActivity(intent);
                    	break;
                    case 2://门店销量
                        intent.setClass(SvSelectVisitContentActivity.this, SvStoreSalesActivity.class);
                        SvSelectVisitContentActivity.this.startActivity(intent);
                        break;
                    case 3: //POSM反馈
                    	intent.setClass(SvSelectVisitContentActivity.this, SvStorePOSMActivity.class);
                        SvSelectVisitContentActivity.this.startActivity(intent);
                    	break;
                    case 4: //竞品信息
                        intent.setClass(SvSelectVisitContentActivity.this, SvStoreCompeteActivity.class);
                        SvSelectVisitContentActivity.this.startActivity(intent);
                        break;
                    case 5: //促销员信息
                        intent.setClass(SvSelectVisitContentActivity.this, SvStorePromoterInfoActivity.class);
                        SvSelectVisitContentActivity.this.startActivity(intent);
                        break;
                    case 6: //特殊任务
                    	intent.setClass(SvSelectVisitContentActivity.this, SpecialTaskActivity.class);
                        SvSelectVisitContentActivity.this.startActivity(intent);
                        break;
                }
            }
        });
    }

    /**
     * BaseAdapter
     */
    private class GridAdapter extends BaseAdapter {

        private class GridHolder {
            TextView mMenuText;
        }

        private LayoutInflater mInflater;

        public GridAdapter() {
            super();
            mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        public int getCount() {
            return mImageId.length;
        }

        @Override
        public Object getItem(int index) {
            return mImageId[index];
        }

        @Override
        public long getItemId(int index) {
            return index;
        }

        /*
         * (non-Javadoc)
         * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
         */
        @Override
        public View getView(int index, View convertView, ViewGroup parent) {
            GridHolder holder;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.grid_item, null);
                holder = new GridHolder();
                holder.mMenuText = (TextView) convertView.findViewById(R.id.text);
                convertView.setTag(holder);

            } else {
                holder = (GridHolder) convertView.getTag();

            }
            holder.mMenuText.setText(mMenuStr[index]);
            holder.mMenuText.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(mImageId[index]), null, null);
            return convertView;
        }
    }
}
